define([ 'jquery', 'knockout','sidenav','headnav','baseview','common'],function($,ko,sidenav,headnav,BaseView,Common){

    var view = BaseView.extend({
        initialize:function(){
            //init navview
            var el_sidenav = $("#sidenav");

            var menuType =Common.Enum.PORTALTYPE.PURCHASE;
            if(window.portaltype == "purchase"){
                menuType =Common.Enum.PORTALTYPE.PURCHASE;
            }
            else if(window.portaltype == "supply"){
                menuType =Common.Enum.PORTALTYPE.SUPPLY;
            }
            else if(window.portaltype == "admin"){
                menuType =Common.Enum.PORTALTYPE.ADMIN;
            }
            else if(window.portaltype == "purchaseadmin"){
                menuType = Common.Enum.PORTALTYPE.PURCHASEADMIN;
            }
            var curUserType = Common.userContext().userType;
            switch(curUserType){
                case "0":menuType =Common.Enum.PORTALTYPE.ADMIN;break;
                case "1":
                    if(Common.userContext().loginName=="supply")
                        menuType =Common.Enum.PORTALTYPE.SUPPLY;
                    else
                        menuType =Common.Enum.PORTALTYPE.PURCHASEADMIN;
                    break;
                case "2":
                    if(Common.userContext().loginName=="supply")
                        menuType =Common.Enum.PORTALTYPE.SUPPLY;
                    else
                        menuType =Common.Enum.PORTALTYPE.PURCHASE;
                    break;
                case "3":
                    if(Common.userContext().loginName=="supply")
                        menuType =Common.Enum.PORTALTYPE.SUPPLY;
                    else
                        menuType =Common.Enum.PORTALTYPE.PURCHASE;
                    break;
                case "4"://如果是销售员
                    menuType =Common.Enum.PORTALTYPE.SUPPLY;
            }
            console.info(menuType);

            ko.applyBindings(new sidenav({el:el_sidenav,menuType:menuType}),el_sidenav[0]);
            //绑定菜单交互事件
            $('#side-menu').metisMenu();
            //init topview
            var el_headnav = $("#topnav");
            ko.applyBindings(new headnav({el:el_headnav}),el_headnav[0]);


            //init Default page
            var cururl = window.location.href.split('#/')[1];
            console.info(cururl)
            if(cururl){
                if(cururl.indexOf("requirelist/0")>0 ||cururl.indexOf("requirelist_new/0")>0 ){
                    cururl = cururl.substring(0,cururl.indexOf('/0'))
                    $("body").data("default-type",0);
                }
                else if(cururl.indexOf("requirelist/1")>0||cururl.indexOf("requirelist_new/1")>0){
                    cururl = cururl.substring(0,cururl.indexOf('/1'))
                    $("body").data("default-type",1);
                }
                window.router.initPage(cururl);
            }
            else{
                if(Common.userContext().loginName=="supply"||curUserType == 4){
                    window.router.initPage("pages/home/supplyhome");
                }
                else{
                    window.router.initPage("pages/home/home");
                }

            }


            //init header

            //init footer
            $("#footer").html(Common.userContext().enterpriseName);
            //return ;
            //init router

        }
    });
    return view;
});